<!DOCTYPE html>
<html>

<head>
<title></title>
<meta http-equiv="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit">

<%include("/common/include.html"){}%>
<style type="text/css">
</style>
</head>

<body class="easyui-layout">
	<table id="upTargetTable" class="easyui-datagrid" style="height:100%;">
		
	</table>
	
	<form id="upTargetForm">
		<input id="targetSumIds" type="hidden" value="${targetSum.ids! }" >
		<div id="tb" style="height:auto">
			起始日期:<input value="${targetSum.startTime! }" class="easyui-textbox theme-textbox-radius"  style="width:15%;" disabled="disabled">
			截止日期:<input value="${targetSum.endTime! }" class="easyui-textbox theme-textbox-radius" style="width:15%;" disabled="disabled">
			目标模式:<input value="${targetSum.codes.name! }" class="easyui-textbox theme-textbox-radius" style="width:15%;" disabled="disabled">
		</div>
	</form>
	
	<script type="text/javascript">
		var $form = $('#upTargetForm');
	
		var submitNow = function($dialog, $grid, $tree, $pjq) {
			if (endEditing()){
				var rows = $('#upTargetTable').datagrid('getChanges');
				for(var i=0;i<rows.length;i++){
					var ids = rows[i].ids;
					var planToStoreNum = rows[i].plantostorenum;
					var delWeiTarget = rows[i].delweitarget;
					$("#upTargetForm").append("<input type='hidden' name='delWeiTargetList["+i+"].ids' value='"+ids+"'/>");
					$("#upTargetForm").append("<input type='hidden' name='delWeiTargetList["+i+"].planToStoreNum' value='"+planToStoreNum+"'/>");
					$("#upTargetForm").append("<input type='hidden' name='delWeiTargetList["+i+"].delWeiTarget' value='"+delWeiTarget+"'/>");
				}
			}
			
			var url = "${cxt!}/bloseWeight/upTarget";
			$.post(url, sy.serializeObject($form), function(result) {
				if (result.code == '200') {
					$dialog.dialog('destroy');
					$.slideMsg("修改成功！", $pjq);
					$grid.datagrid('reload');
					
				} else {
					$.alert($pjq, result.msg);
				}
			}, 'json');
		};
		var submitForm = function($dialog, $grid, $tree, $pjq) {
			submitNow($dialog, $grid, $tree, $pjq);
			// 					$form.isValid(function(isValied){
			// 						if(isValied){
			// 							submitNow($dialog, $grid, $pjq);
			// 						}
			// 					});
		};
		(function($){
			initTargetTable($("#targetSumIds").val());
		})(jQuery);
		
		//初始化目标table
		function initTargetTable(targetSumIds){
			$('#upTargetTable').datagrid({
				cls: "theme-datagrid",
				toolbar: '#tb',
				singleSelect: true,
				rownumbers: true, //显示序号
				url: "${cxt!}/bloseWeight/getTargets?ids=" + targetSumIds,
			    method: 'post',
				columns:[[	
							{field:'ids',title:'ids',width:100,align:'center', hidden:true},
							{field:'schedule',title:'排期',width:100,align:'center'},
							{field:'starttime',title:'起始日期',width:100,align:'center'},
							{field:'endtime',title:'截止日期',width:100,align:'center'},
							{field:'plantostorenum',title:'计划到店次数',width:100,align:'center',editor:'numberspinner'},
							{field:'delweitarget',title:'减重目标（斤）',width:100,align:'center',editor:'numberspinner'}
					    ]],
				onLoadSuccess:function(){
		        	
				},
				onClickRow:function(index, rowData){
					if (editIndex != index){
						if (endEditing()){
							$('#upTargetTable').datagrid('selectRow', index)
									.datagrid('beginEdit', index);
							editIndex = index;
						} else {
							$('#upTargetTable').datagrid('selectRow', editIndex);
						}
					}
				}
			});
		}
		
	</script>
	<script type="text/javascript">
		var editIndex = undefined;
		function endEditing(){
			if (editIndex == undefined){return true}
			if ($('#upTargetTable').datagrid('validateRow', editIndex)){
				$('#upTargetTable').datagrid('endEdit', editIndex);
				editIndex = undefined;
				return true;
			} else {
				return false;
			}
		}
	</script>

</body>
</html>